﻿using System;
using UnityEngine;
using UnityEngine.UI;

namespace SizeboxUI
{
	// Token: 0x02000393 RID: 915
	public class CatalogView : MonoBehaviour
	{
		// Token: 0x060017EB RID: 6123 RVA: 0x000978B0 File Offset: 0x00095AB0
		private void Start()
		{
			this.control = Camera.main.GetComponent<InterfaceControl>();
			this.placement = this.control.GetComponent<EditPlacement>();
			this.saved_playAsGts = false;
			this.saved_playAsMicro = false;
			this.toggles = base.GetComponentsInChildren<Toggle>();
			foreach (Toggle toggle in this.toggles)
			{
				if (toggle.gameObject.name == "PlayAsGts")
				{
					this.playAsGiantess = toggle;
				}
				else if (toggle.gameObject.name == "AlternateShaders")
				{
					this.useAlternateShaders = toggle;
				}
				else if (toggle.gameObject.name == "AlternateShadowing")
				{
					this.useAlternateTangents = toggle;
				}
			}
			this.playAsGiantess.isOn = false;
			this.useAlternateShaders.isOn = false;
			this.useAlternateTangents.isOn = false;
			Button[] componentsInChildren = base.GetComponentsInChildren<Button>();
			componentsInChildren[0].onClick.AddListener(delegate()
			{
				this.OnPrevious();
			});
			componentsInChildren[1].onClick.AddListener(delegate()
			{
				this.OnNext();
			});
			componentsInChildren[2].onClick.AddListener(delegate()
			{
				this.OnMale();
			});
			componentsInChildren[3].onClick.AddListener(delegate()
			{
				this.OnFemale();
			});
			this.microGenderButtonsPanel = componentsInChildren[2].transform.parent.gameObject;
			this.microGenderButtonsPanel.SetActive(false);
			this.playAsGiantess.gameObject.SetActive(false);
			this.useAlternateShaders.gameObject.SetActive(false);
			this.useAlternateTangents.gameObject.SetActive(false);
			this.placeholder = (Resources.Load("UI/Button/ThumbPlaceholder") as GameObject);
			this.grid = base.GetComponentInChildren<GridLayoutGroup>();
			RectTransform component = this.grid.GetComponent<RectTransform>();
			int num = (int)component.rect.width / 72;
			int num2 = (int)component.rect.height / 84;
			this.thumbCount = num * num2;
			this.thumbs = new Image[this.thumbCount];
			for (int j = 0; j < this.thumbCount; j++)
			{
				GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.placeholder, this.grid.transform);
				gameObject.name = "Thumbnail " + j;
				this.thumbs[j] = gameObject.GetComponent<Image>();
				this.originalColor = this.thumbs[j].color;
				Button component2 = gameObject.GetComponent<Button>();
				int number = j;
				component2.onClick.AddListener(delegate()
				{
					this.OnElementClick(number);
				});
			}
			this.SetCategory(0);
			base.gameObject.SetActive(false);
		}

		// Token: 0x060017EC RID: 6124 RVA: 0x00097B9C File Offset: 0x00095D9C
		public void OnMenuClick(int category)
		{
			if (category == this.currentCatalog)
			{
				base.gameObject.SetActive(!base.gameObject.activeSelf);
			}
			else
			{
				this.SetCategory(category);
				base.gameObject.SetActive(true);
			}
		}

		// Token: 0x060017ED RID: 6125 RVA: 0x00097BDC File Offset: 0x00095DDC
		public void SetCategory(int category)
		{
			if (this.currentCatalog != category)
			{
				if (category == 3 || category == 4)
				{
					if (this.currentCatalog == 1)
					{
						this.saved_playAsGts = this.playAsGiantess.isOn;
					}
					this.playAsGiantess.GetComponentInChildren<Text>().text = "Play as Spawned Micro";
					this.playAsGiantess.isOn = this.saved_playAsMicro;
					this.microGenderButtonsPanel.SetActive(true);
					this.playAsGiantess.gameObject.SetActive(true);
					this.useAlternateShaders.gameObject.SetActive(false);
					this.useAlternateTangents.gameObject.SetActive(false);
				}
				else if (category == 1)
				{
					if (this.currentCatalog == 3 || this.currentCatalog == 4)
					{
						this.saved_playAsMicro = this.playAsGiantess.isOn;
					}
					this.playAsGiantess.GetComponentInChildren<Text>().text = "Play as Spawned Giantess";
					this.playAsGiantess.isOn = this.saved_playAsGts;
					this.microGenderButtonsPanel.SetActive(false);
					this.playAsGiantess.gameObject.SetActive(true);
					this.useAlternateShaders.gameObject.SetActive(true);
					this.useAlternateTangents.gameObject.SetActive(true);
				}
				else
				{
					this.microGenderButtonsPanel.SetActive(false);
					this.playAsGiantess.gameObject.SetActive(false);
					this.useAlternateShaders.gameObject.SetActive(false);
					this.useAlternateTangents.gameObject.SetActive(false);
				}
			}
			this.currentCatalog = category;
			this.page = 0;
			this.pageCount = this.control.catalog[this.currentCatalog].Length / this.thumbCount + 1;
			this.LoadPage(this.page);
		}

		// Token: 0x060017EE RID: 6126 RVA: 0x00097DA4 File Offset: 0x00095FA4
		private void LoadPage(int pag)
		{
			int num = pag * this.thumbCount;
			for (int i = 0; i < this.thumbCount; i++)
			{
				int num2 = num + i;
				if (num2 < this.control.catalog[this.currentCatalog].Length)
				{
					this.thumbs[i].sprite = this.control.catalog[this.currentCatalog][num2];
					this.thumbs[i].color = Color.white;
					this.thumbs[i].GetComponentInChildren<Text>().text = this.thumbs[i].sprite.name.Split(new char[]
					{
						'.'
					})[0];
				}
				else
				{
					this.thumbs[i].sprite = null;
					this.thumbs[i].color = this.originalColor;
					this.thumbs[i].GetComponentInChildren<Text>().text = string.Empty;
				}
			}
		}

		// Token: 0x060017EF RID: 6127 RVA: 0x00097EA0 File Offset: 0x000960A0
		private void OnElementClick(int i)
		{
			if (this.thumbs[i].sprite)
			{
				string name = this.thumbs[i].sprite.name;
				if (this.control.selectedEntity != null && !this.control.selectedEntity.isPositioned)
				{
					this.control.selectedEntity.DestroyObject(true);
				}
				switch (this.currentCatalog)
				{
				case 0:
					this.placement.AddGameObject(name);
					break;
				case 1:
					if (this.playAsGiantess.isOn)
					{
						this.control.PlayAsGiantess(name, this.useAlternateShaders.isOn, this.useAlternateTangents.isOn);
					}
					else
					{
						this.placement.AddGiantess(name, this.useAlternateShaders.isOn, this.useAlternateTangents.isOn);
					}
					break;
				case 3:
					this.placement.AddMicro(name, true, this.playAsGiantess.isOn);
					break;
				case 4:
					this.placement.AddMicro(name, false, this.playAsGiantess.isOn);
					break;
				}
			}
		}

		// Token: 0x060017F0 RID: 6128 RVA: 0x00097FE2 File Offset: 0x000961E2
		private void OnMale()
		{
			this.SetCategory(4);
		}

		// Token: 0x060017F1 RID: 6129 RVA: 0x00097FEB File Offset: 0x000961EB
		private void OnFemale()
		{
			this.SetCategory(3);
		}

		// Token: 0x060017F2 RID: 6130 RVA: 0x00097FF4 File Offset: 0x000961F4
		private void OnNext()
		{
			this.page++;
			if (this.page >= this.pageCount)
			{
				this.page = 0;
			}
			this.LoadPage(this.page);
		}

		// Token: 0x060017F3 RID: 6131 RVA: 0x00098028 File Offset: 0x00096228
		private void OnPrevious()
		{
			this.page--;
			if (this.page < 0)
			{
				this.page = this.pageCount - 1;
			}
			this.LoadPage(this.page);
		}

		// Token: 0x04001A20 RID: 6688
		private GameObject placeholder;

		// Token: 0x04001A21 RID: 6689
		private int thumbCount;

		// Token: 0x04001A22 RID: 6690
		private GridLayoutGroup grid;

		// Token: 0x04001A23 RID: 6691
		private InterfaceControl control;

		// Token: 0x04001A24 RID: 6692
		private Image[] thumbs;

		// Token: 0x04001A25 RID: 6693
		private EditPlacement placement;

		// Token: 0x04001A26 RID: 6694
		private int currentCatalog;

		// Token: 0x04001A27 RID: 6695
		private Color originalColor;

		// Token: 0x04001A28 RID: 6696
		private int page;

		// Token: 0x04001A29 RID: 6697
		private int pageCount;

		// Token: 0x04001A2A RID: 6698
		private GameObject MicroButtons;

		// Token: 0x04001A2B RID: 6699
		private Toggle[] toggles;

		// Token: 0x04001A2C RID: 6700
		private Toggle playAsGiantess;

		// Token: 0x04001A2D RID: 6701
		private Toggle useAlternateShaders;

		// Token: 0x04001A2E RID: 6702
		private Toggle useAlternateTangents;

		// Token: 0x04001A2F RID: 6703
		private GameObject microGenderButtonsPanel;

		// Token: 0x04001A30 RID: 6704
		private bool saved_playAsGts;

		// Token: 0x04001A31 RID: 6705
		private bool saved_playAsMicro;
	}
}
